<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="../js/vue.js"></script>
    <link rel="stylesheet" href="../css/animate.css">
    <style>
        .box{
            width:170px;
            height:170px;
            background: darkcyan;
        }
    </style>
</head>
<body>
    <div id="app">
        <h2>{{title}} </h2>
        <myhead></myhead>
        <parent></parent>
    </div>

    <template id="parent">
        <div>
            <h2 ref="one">I am parent  父组件 - 1</h2>
            <h2>word -- {{word}}</h2>
            <h2 @click="count++">count -- {{count}} </h2>
            <p>
                <input type="text" v-model="word">
            </p>
            <button @click="show =!show">切换{{show?'隐藏':'显示'}}</button>
            <button @click="changChildOne">通过refs 去操作子组件1</button>
            <hr>
            <childone
                :word="word"
                :count="count"
                ref="child1"
            ></childone>      
            <hr>
            <childtwo
                :show="show"
                ref="child2"
            ></childtwo>
        </div>
    </template>

    <template id="childone">
        <div>
            <h2>childone - 1 - 子组件</h2>
            <h2>props --- {{word}} - {{count}} </h2>
            <h2>num --- {{num}} </h2>
        </div>
    </template>

    <template id="childtwo">
        <div>
            <h2>childtwo - 2 - 子组件</h2>
           <div v-if="show" class="box">我是被父组件控制的</div>
        </div>
    </template>


    <script>
        Vue.component('myhead',{
            template:"<h1>越努力越幸运</h1>"
        })

        Vue.component('parent',{
            template:'#parent',
            data(){
                return{
                    word:"Are you Ok?",
                    count:1000,
                    show:true
                }
            },
            mounted(){
                this.$refs.one.style.color = 'pink'
            },
            methods:{
                changChildOne(){
                    this.$refs.child1.num += 10;
                    this.$refs.child1.greet()
                }
            },

            components:{
                childtwo:{
                    template:'#childtwo',
                    props:{
                        
                        show:Boolean,
                        
                    }
                }
            }
        })

        Vue.component('childone',{
            template:"#childone",
            props:[
                'word',
                'count',
            ],
            methods:{
                greet(){
                    console.log("greeting - 周末去哪里玩...");
                }
            },
            data(){
                return{
                    num:2000
                }
            }
                
            
        })

       

    
        const vm = new Vue({

            data:{
                title:"Vue component 组件通讯(父子 兄弟)",
            },
            components:{ //局部变量
                frist:{
                    template:"<h3>frist - Vue 组件初始化</h3>"
                }
            },
            mounted(){
                document.getElementsByTagName("title")[0].innerHTML = this.title
            },

        }).$mount('#app')
    </script>
</body>
</html>